package io.gitee.chearnee.fw.web.entity;

import cn.hutool.extra.spring.SpringUtil;
import lombok.*;
import org.springframework.core.ResolvableType;

/**
 * @author cn
 * @version 1.0
 * @description
 * @date 2022/5/11 15:52
 */
public class BaseDo<T> {

  public BaseDo() {
    getGateway();
  }

  private void getGateway() {
    if (gateway != null) {
      return;
    }
    synchronized (this) {
      if (gateway != null) {
        return;
      }
      //获取当前类的泛型类型
      gateway = (T) SpringUtil.getBean(
          ResolvableType.forClass(this.getClass()).getSuperType().resolveGeneric(0));
    }
  }

  @ToString.Exclude
  @EqualsAndHashCode.Exclude
  @Getter(AccessLevel.NONE)
  @Setter(AccessLevel.NONE)
  protected T gateway;
}
